package com.aotao.springboot.impl;

import com.aotao.springboot.domain.*;
import com.aotao.springboot.mapper.ArticleMapper;
import com.aotao.springboot.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.management.relation.Role;
import java.util.List;

@Service
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    private ArticleMapper articleMapper;

    @Override
    public List<Article> getArticle() {
        return this.articleMapper.getArticle();
    }

    @Override
    public int insertArticle(Article article) {
        System.out.println("执行了几次？");
        return articleMapper.insertArticle(article);
    }

    @Override
//    @Transactional(propagation= Propagation.REQUIRED,isolation= Isolation.READ_COMMITTED)
    public void insertArticleTag(Article article, ArticleTag tag) {
        articleMapper.insertArticleTag(article, tag);
    }

    @Override
    public ArticleTag queryTagByName(String tagName) {
        return articleMapper.queryTagByName(tagName);
    }

    @Override
    public List<ArticleType> queryAllTypes() {
        return articleMapper.queryAllTypes();
    }

    @Override
    public Article queryArticleByID(int id) {
        return articleMapper.queryArticleByID(id);
    }

    @Override
    public int updateArticle(Article article) {
        return articleMapper.updateArticle(article);
    }

    @Override
    public int updateArticleTag(Article article, ArticleTag tag) {
        return articleMapper.updateArticleTag(article,tag);
    }

    @Override
    public int deleteArticleToTagByArticleID(int id) {
        return articleMapper.deleteArticleToTagByArticleID(id);
    }

    @Override
    public List<ArticleTag> queryAllTags() {
        return articleMapper.queryAllTags();
    }

    @Override
    public int insertTypes(ArticleType typeName) {
        return articleMapper.insertTypes(typeName);
    }

    @Override
    public int updateType(ArticleType articleType) {
        return articleMapper.updateType(articleType);
    }

    @Override
    public int deleteTypeByID(int did) {
        return articleMapper.deleteTypeByID(did);
    }

    @Override
    public int updateArticleForType(int did) {
        return articleMapper.updateArticleForType(did);
    }
}
